package com.example.myapplication.request

import androidx.lifecycle.MutableLiveData
import com.example.myapplication.bean.ListResultBean
import com.example.myapplication.bean.coins.CoinInfoBean
import com.example.myapplication.bean.coins.CoinRecordBean
import com.kun.base.net.Api
import com.kun.base.net.ResponseResult

/**
 *积分相关的请求
 *
 * @author : Kun
 * @date : 2021/6/10
 * @time : 17:11
 */
class CoinsRequest {
    /**
     * 用户积分的结果
     */
    val userCoinsResult = MutableLiveData<ResponseResult<CoinInfoBean>>()

    /**
     * 排行榜结果
     */
    val rankListResult = MutableLiveData<ResponseResult<ListResultBean<CoinInfoBean>>>()

    /**
     * 获取积分排行
     */
    val coinRecordListResult = MutableLiveData<ResponseResult<ListResultBean<CoinRecordBean>>>()

    /**
     * 获取用户积分
     */
    suspend fun requestUserCoinsResult() {
        userCoinsResult.value = Api.apiCall {
            Api.getInstance(IApi::class.java).getUserCoins()
        }
    }

    /**
     * 获取排行榜结果
     */
    suspend fun requestRankListResult(index: Int) {
        rankListResult.value = Api.apiCall {
            Api.getInstance(IApi::class.java).getRankList(index)
        }
    }

    /**
     * 获取排行榜结果
     */
    suspend fun requestCoinRecordList(index: Int) {
        coinRecordListResult.value = Api.apiCall {
            Api.getInstance(IApi::class.java).getCoinRecordList(index)
        }
    }
}